package com.ivan.stu.notetool.network.intercepter;

import android.util.Log;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by IVAN on 2018/11/12.
 */

public class RequestHeaderInterceptor implements Interceptor {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            Log.e("url",originalRequest.url().toString());
            String url = originalRequest.url().toString();

            if (url.contains("V2")&&url.contains("Notes")&&!url.contains("UploadNoteSourceInfo")){  //需要加密的请求

                Request updateRequest = originalRequest.newBuilder()
                        .header("Content-Type", "application/json; charset=utf-8")
                        .header("Accept", "*/*")
                        .header("Accept-Encoding", "gzip")
                        .build();
                return chain.proceed(updateRequest);

            }else {  //不需要加密的请求

                return chain.proceed(originalRequest);

            }
        }
}
